<?php
/**
 * Created by PhpStorm.
 * User: yangjiaming
 * Date: 2018/2/6
 * Time: 16:53
 */

namespace Eagle\Service;


class RedisHelper
{
    public static function getToken()
    {
        $TokenToUserKey = 'TokenToUser_';
        if(empty($_COOKIE['token'])) {
            return '';
        }
        $token = $_COOKIE['token'];
        $v = EagleRedis::get($TokenToUserKey . $token);
        if(!empty($v)) {
            $v = EagleRedis::get('userInfo_' . $v);
        }
        return $v;
    }
    public static function setToken($userInfo)
    {
        $token = substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'), 0, 48);
        $login_token = substr(str_shuffle('0123456789'), 0, 6);
        setcookie('token', $token, 0);
        $TokenToUserKey = 'TokenToUser_';
        EagleRedis::set($TokenToUserKey . $token, $login_token);
        EagleRedis::set('userInfo_' . $login_token, json_encode($userInfo));

    }
}